<template>
  <div class="login-setting">
    <el-form
      ref="userForm"
      :rules="rules"
      :model="userInfo"
      label-width="120px"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>

      <el-form-item label="密码:" prop="password">
        <el-input v-model="userInfo.password" type="password" style="width:300px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="updateUser">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserDetailById } from '@/api/user'
// api接口
import { saveUserDetailById } from '@/api/exployee'
export default {
  name: 'LoginSetting',
  data() {
    return {
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [{
          required: true, message: '请输入用户名', trigger: 'blur'
        }],
        password: [{
          required: true, message: '请输入密码', trigger: 'blur'
        }]
      }
    }
  },
  created() {
    // 调用用户详情信息方法
    this.getUserDetailByIdFn()
  },
  methods: {
    // 更新用户信息
    updateUser() {
      this.$refs.userForm.validate(async valid => {
        if (!valid) return
        const res = await saveUserDetailById(this.userInfo)
        console.log(res)

        this.$message.success(res.message)// 成功提示
      })
    },
    // 获取用户详情信息
    async getUserDetailByIdFn() {
      const res = await getUserDetailById(this.$route.query.id)// 路径传参
      // console.log(res)
      // this.$message.success(res.message)// 成功提示
      this.userInfo = res.data// 数据铺设上去
    }
  }
}
</script>

   <style lang="scss" scoped></style>

